package cn.k7g.alloytest.mold.func;

import cn.k7g.alloy.annotation.MoldMethod;
import cn.k7g.alloy.annotation.MoldObject;
import cn.k7g.alloy.mold.var.AbsVar;
import cn.k7g.alloytest.mold.model.Student;
import cn.k7g.alloytest.mold.model.Teacher;
import cn.k7g.alloytest.mold.var.StudentVar;
import cn.k7g.alloytest.mold.var.TeacherVar;

@MoldObject
public class GlobalFunc {
    public String getVersion() {
        return "version: 1.0.0";
    }

    @MoldMethod
    public String hello(String name) {
        return "hello " + name;
    }

    @MoldMethod
    public String link(Object obj, AbsVar var) {
        if (var instanceof StudentVar) {
            Student stu = (Student) obj;
            return String.format("<a href='http://xxx/student/%s'>%s</a>", stu.getId(), stu.getName());
        }

        if (var instanceof TeacherVar) {
            Teacher stu = (Teacher) obj;
            return String.format("<a href='http://xxx/teacher/%s'>%s</a>", stu.getId(), stu.getName());
        }
        return "无超链接";
    }
}
